<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  <title>08-函数进阶</title>
  <style type="text/css">
  * {
    padding: 0;
    margin: 0;
  }

  body {
    width: 100vw;
    height: 100vh;
    font-size: 3em;
    padding: 30px;
    transition: 1s;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #34495e;
    color: #34495e;
  }

  div {
    width: 350px;
    height: 350px;
    border: 1px solid black;
 transition: 1s;
  }
  </style>
</head>
<body>
  <div id="box" class="box">
    这是一个div
  </div>
  <script src="index.js"></script>
  <script type="text/javascript">
  function Color(elem) {
    this.elem = elem;
    this.colors = ["#74b9ff", "#ffeaa7", "#fab1a0", "#fd79a8"];

  }

  Color.prototype.run = function() {
    setInterval(function() {
      let pos = Math.floor(Math.random() * this.colors.length)
      this.elem.style.background = this.colors[pos]
    }.bind(this), 1000)
  }

  new Color(document.body).run()
  new Color(box).run()
  </script>
</body>
</html>